package me.zhengjie.hr.employeebase.domain;

import lombok.Data;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import me.zhengjie.org.centerbase.domain.CenterBase;
import org.hibernate.annotations.ColumnTransformer;

import javax.persistence.*;
import javax.validation.constraints.*;
import java.sql.Timestamp;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* @author ZGZ
* @date 2020-04-15
*/
@Entity
@Data
@Table(name="employee_base")
public class EmployeeBase implements Serializable {

    /** ID */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Integer id;

    /** 姓名 */
    @Column(name = "emp_name")
    private String empName;

    /** 性别 */
    @Column(name = "sex")
    private String sex;

    /** 出生日期 */
    @Column(name = "birthday")
    private Timestamp birthday;

    /** 身份证 */
    @Column(name = "id_card")
//    @ColumnTransformer(
//            read = "CAST(AES_DECRYPT(UNHEX(id_card), 'rjb') as char(128))",
//            write = "HEX(AES_ENCRYPT(?, 'rjb'))"
//    )
    private String idCard;

    /** 入所时间 */
    @Column(name = "`join`")
    private Timestamp join;

    /** 籍贯 */
    @Column(name = "native_place")
    private String nativePlace;

    /** 民族 */
    @Column(name = "nation")
    private String nation;

    /** 最高学历 */
    @Column(name = "highest_edu")
    private String highestEdu;

    /** 最高学位 */
    @Column(name = "highest_degree")
    private String highestDegree;

    /** 学校1（本科） */
    @Column(name = "first_school")
    private String firstSchool;

    /** 专业1 */
    @Column(name = "first_major")
    private String firstMajor;

    /** 学校2（研究生） */
    @Column(name = "second_school")
    private String secondSchool;

    /** 专业2 */
    @Column(name = "second_major")
    private String secondMajor;

    /** 职称 */
    @Column(name = "title")
    private String title;

    /** 获得此职称的时间 */
    @Column(name = "title_begin_time")
    private Timestamp titleBeginTime;

    /** 专业等级 */
    @Column(name = "professional_level")
    private String professionalLevel;

    /** 手机号 */
    @Column(name = "phone")
//    @ColumnTransformer(
//            read = "CAST(AES_DECRYPT(UNHEX(phone), 'rjb') as char(128))",
//            write = "HEX(AES_ENCRYPT(?, 'rjb'))"
//    )
    private String phone;

    /** 联系人 */
    @Column(name = "relation_member")
    private String relationMember;

    /** 联系人手机号 */
    @Column(name = "family_phone")
//    @ColumnTransformer(
//            read = "CAST(AES_DECRYPT(UNHEX(family_phone), 'rjb') as char(128))",
//            write = "HEX(AES_ENCRYPT(?, 'rjb'))"
//    )
    private String familyPhone;

    /** 家庭住址（详细） */
    @Column(name = "address")
//    @ColumnTransformer(
//            read = "CAST(AES_DECRYPT(UNHEX(address), 'rjb') as char(128))",
//            write = "HEX(AES_ENCRYPT(?, 'rjb'))"
//    )
    private String address;

    /** 婚姻情况 */
    @Column(name = "marital_status")
    private String maritalStatus;

    /** 子女情况 */
    @Column(name = "children_situation")
    private String childrenSituation;

    /** 政治面貌 */
    @Column(name = "politics_status")
    private String politicsStatus;

    /** 涉密等级 */
    @Column(name = "secret_level")
    private String secretLevel;

    /** 工作证编号 */
    @Column(name = "worker_number")
    private String workerNumber;

    /** 邮箱 */
    @Column(name = "email")
//    @ColumnTransformer(
//            read = "CAST(AES_DECRYPT(UNHEX(email), 'rjb') as char(128))",
//            write = "HEX(AES_ENCRYPT(?, 'rjb'))"
//    )
    private String email;

    /** 所属中心 */
//    @Column(name = "center_belong")
//    private Integer centerBelong;
//    @OneToOne
//    @JoinColumn(name = "center_belong")
//    private CenterBase centerBelong;
    @Column(name = "center_belong")
    private Integer centerBelong;
    @OneToOne
    @JoinColumn(name = "center_belong", insertable = false, updatable = false)
    private CenterBase centerBase;
//    @Column(name = "center_belong")
//    private Integer centerBelong;
//    @ManyToOne
//    @JoinColumn(name = "center_belong", insertable = false, updatable = false, nullable=true)
//    private CenterBase centerBase;

    /** 离职时间 */
    @Column(name = "leave_time")
    private Timestamp leaveTime;

    /** 离职原因 */
    @Column(name = "leave_reason")
    private String leaveReason;

    /** 离职说明 */
    @Column(name = "leave_inf")
    private String leaveInf;

    /** 前单位 */
    @Column(name = "former_unit")
    private String formerUnit;

    /** 是否离职 */
    @Column(name = "is_leave")
    private String isLeave;

    public void copy(EmployeeBase source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }
}